//
//  OfflinePresentation.swift
//  I.S.A.P WT
//
//  Created by Илья Проскурнев on 18.05.2020.
//  Copyright © 2020 Илья Проскурнев. All rights reserved.
//

import SwiftUI

class OfflinePresentation: UIViewController, SASRadioButtonDelegate, RACRadioButtonDelegate, EERadioButtonDelegate{
    
    
    @IBOutlet weak var accyracy: UILabel!
    @IBOutlet weak var presentation: UILabel!
    @IBOutlet weak var total: UILabel!
    
    var sasRadioButton: SASRadioButton?
    var racRadioButton: RACRadioButton?
    var eeRadioButton: EERadioButton?
    var presentationOc: Int!
    
    var pr1 = 20
    var pr2 = 20
    var pr3 = 20
    var sc: String!
    
    var Acd: Double!
    var num01: Int!
    var num03: Int!
    
    @IBOutlet weak var sas20: UIButton!
    @IBOutlet weak var sas19: UIButton!
    @IBOutlet weak var sas18: UIButton!
    @IBOutlet weak var sas17: UIButton!
    @IBOutlet weak var sas16: UIButton!
    @IBOutlet weak var sas15: UIButton!
    @IBOutlet weak var sas14: UIButton!
    @IBOutlet weak var sas13: UIButton!
    @IBOutlet weak var sas12: UIButton!
    @IBOutlet weak var sas11: UIButton!
    @IBOutlet weak var sas10: UIButton!
    @IBOutlet weak var sas09: UIButton!
    @IBOutlet weak var sas08: UIButton!
    @IBOutlet weak var sas07: UIButton!
    @IBOutlet weak var sas06: UIButton!
    @IBOutlet weak var sas05: UIButton!
    
    @IBOutlet weak var rac20: UIButton!
    @IBOutlet weak var rac19: UIButton!
    @IBOutlet weak var rac18: UIButton!
    @IBOutlet weak var rac17: UIButton!
    @IBOutlet weak var rac16: UIButton!
    @IBOutlet weak var rac15: UIButton!
    @IBOutlet weak var rac14: UIButton!
    @IBOutlet weak var rac13: UIButton!
    @IBOutlet weak var rac12: UIButton!
    @IBOutlet weak var rac11: UIButton!
    @IBOutlet weak var rac10: UIButton!
    @IBOutlet weak var rac09: UIButton!
    @IBOutlet weak var rac08: UIButton!
    @IBOutlet weak var rac07: UIButton!
    @IBOutlet weak var rac06: UIButton!
    @IBOutlet weak var rac05: UIButton!
    
    @IBOutlet weak var ee20: UIButton!
    @IBOutlet weak var ee19: UIButton!
    @IBOutlet weak var ee18: UIButton!
    @IBOutlet weak var ee17: UIButton!
    @IBOutlet weak var ee16: UIButton!
    @IBOutlet weak var ee15: UIButton!
    @IBOutlet weak var ee14: UIButton!
    @IBOutlet weak var ee13: UIButton!
    @IBOutlet weak var ee12: UIButton!
    @IBOutlet weak var ee11: UIButton!
    @IBOutlet weak var ee10: UIButton!
    @IBOutlet weak var ee09: UIButton!
    @IBOutlet weak var ee08: UIButton!
    @IBOutlet weak var ee07: UIButton!
    @IBOutlet weak var ee06: UIButton!
    @IBOutlet weak var ee05: UIButton!
    
    @IBOutlet weak var sas: UILabel!
    @IBOutlet weak var rac: UILabel!
    @IBOutlet weak var ee: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        sasRadioButton = SASRadioButton(buttons: sas20, sas19, sas18, sas17, sas16, sas15, sas14, sas13, sas12, sas11, sas10, sas09, sas08, sas07, sas06, sas05)
        sasRadioButton!.delegate = self
        sasRadioButton!.shouldLetDeSelect = true
        
        racRadioButton = RACRadioButton(buttons: rac20, rac19, rac18, rac17, rac16, rac15, rac14, rac13, rac12, rac11, rac10, rac09, rac08, rac07, rac06, rac05)
        racRadioButton!.delegate = self
        racRadioButton!.shouldLetDeSelect = true
        
        eeRadioButton = EERadioButton(buttons: ee20, ee19, ee18, ee17, ee16, ee15, ee14, ee13, ee12, ee11, ee10, ee09, ee08, ee07, ee06, ee05)
        eeRadioButton!.delegate = self
        eeRadioButton!.shouldLetDeSelect = true
        
        accyracy.text = String(Acd)
        printScoring()
    }
    
    func sasSelectButton(selectedButton: UIButton?)
    {
        sas.text = selectedButton?.currentTitle
        pr1 = Int(Double(selectedButton?.currentTitle ?? "2.0")!*10)
        printScoring()
    }
    
    func racSelectButton(selectedButton: UIButton?)
    {
        rac.text = selectedButton?.currentTitle
        pr2 = Int(Double(selectedButton?.currentTitle ?? "2.0")!*10)
        printScoring()
    }
    
    func eeSelectButton(selectedButton: UIButton?)
    {
        ee.text = selectedButton?.currentTitle
        pr3 = Int(Double(selectedButton?.currentTitle ?? "2.0")!*10)
        printScoring()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    func printScoring() {
        let sc = String(Acd)
        let ac = Int(Acd*10)
        accyracy.text = sc
        presentation.text = String(Double(pr1+pr2+pr3)/Double(10))
        total.text = String(Double(pr1+pr2+pr3+ac)/Double(10))
    }
    
    
}
